#include <iostream>

using namespace std;

#define maxn 71

long long N;
long long f[maxn], ff[maxn]; // f[70] == 308061521170129
long long s[maxn], ss[maxn];
long long val, result;
int k; // length of number at N

void init()
{
	f[0] = 1; ff[0] = 1;
	f[1] = 1; ff[1] = 2;
	for (int i = 2; i <= maxn; i++)
	{
		f[i] = f[i-1] + f[i-2];
		ff[i] = f[i] + ff[i-1];
	}

	s[0] = 0; ss[0] = 0;
	s[1] = 1; ss[1] = 1;
	s[2] = 1; ss[2] = 2;

	for (int i = 3; i <= maxn; i++)
	{
		s[i] = f[i-1] + ss[i-2];
		ss[i] = s[i] + ss[i-1];
	}
}

int main()
{
	init();

	while (cin >> N)
	{

	int k = 1;
	while (true)
	{
		if (N <= k*f[k-1]) break;
		N -= k*f[k-1];
		k++;
	}

	long long nPrev = (N-1)/k, nPos = (N-1) % k + 1;
	if (k-2 < 0) val = 0; else val = ff[k-2];
	val += nPrev + 1;

	result = 0;
	int ccount = 0, c1 = -1;
	for (int i = maxn; i >= 0; i--)
	{
		if (val - f[i] >= 0)
		{
			val -= f[i];

			result += ss[i-1] + (f[i-2]+1)*ccount;

			if (i == k-1) c1 = 1;
			else
				if (i < k-1) c1++;
			if (c1 == nPos) result += ccount;

			ccount++;
		}

		if (i == k-1) c1 = 1;
		else
			if (i < k-1) c1++;
		if (c1 == nPos) result += ccount;
	}

	cout << result << endl;
	}

	return 0;
}
